let arrayProto = Array.prototype;

let arrayMethods = Object.create(arrayProto);

let methodsToPatch = [
    "push",
    "pop",
    "shift",
    "unshift",
    "splice",
    "sort",
    "reverse",
]

methodsToPatch.forEach(method => {
    arrayMethods[method] = function(...args) {
        const result = arrayProto[method].call(this, ...args);
        let inserted;
        const ob = this.__ob__;
        switch (method) {
            case 'push':
            case 'unshift':
                inserted = args;                
                break;
            case 'splice':
                inserted = args.slice(2);
            default:
                break;
        }
        if(inserted) {
            ob.observeArray(inserted);
        }
        return result;
    }
})

export default arrayMethods;